package com.fbt.andon.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fbt.andon.domain.Hour;
import com.fbt.andon.service.impl.HourServiceImpl;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 每小时时产量Controller
 *
 * @author fengtao
 * @date 2021-08-13
 */
@RestController
@RequestMapping("/hour")
@Api(description = "每小时产量api")
public class HourController extends BaseController {
    @Autowired
    private HourServiceImpl hourService;

    /**
     * 查询该表所有信息
     */
    @GetMapping("/getHour")
    @ApiOperation("查询该表所有信息")
    public AjaxResult findNgList() {
        startPage();
        return AjaxResult.success("查询成功", hourService.list(null));
    }


    //    //@PreAuthorize(hasPermi = "andon:line:list")
    @GetMapping("/groupList")
    @ApiOperation("根据日期查找每日产量")
    public AjaxResult queryList(String amountDate) {

        QueryWrapper<Hour> wrapper = new QueryWrapper<>();
        wrapper.like("amount_date", amountDate);
        return AjaxResult.success("查询成功", hourService.list(wrapper));
    }


    /**
     * 获取每小时时产量详细信息
     */
//    //@PreAuthorize(hasPermi = "andon:hour:query")
    @ApiOperation("获取每小时时产量详细信息，参数id")
    @GetMapping("/get/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success("获取成功", hourService.getById(id));
    }

    /**
     * 新增每小时时产量
     */
//    //@PreAuthorize(hasPermi = "andon:hour:add")
    @ApiOperation("新增每小时时产量，参数hour")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Hour hour) {
        return AjaxResult.success("新增成功", hourService.save(hour));
    }

    /**
     * 修改每小时时产量
     */
//    //@PreAuthorize(hasPermi = "andon:hour:edit")
    @ApiOperation("修改每小时时产量，参数hour")
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody Hour hour) {
        return AjaxResult.success("修改成功", hourService.updateById(hour));
    }

    /**
     * 删除每小时时产量
     *
     * @return
     */
//    //@PreAuthorize(hasPermi = "andon:hour:remove")
    @ApiOperation("批量删除每小时时产量，参数ids")
    @PostMapping("/batchRemove/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return AjaxResult.success("删除成功", hourService.removeByIds(Arrays.asList(ids)));
    }
}
